package com.poly_.polyarr_;

public class PolyArray {
    public static void main(String[] args) {
        /**
         * 多态数组：
         * */
        Person[] people = new Person[5];
        people[0] = new Person("jack",18);
        people[1] = new Student("joy",20,60);
        people[2] = new Student("mary",21,70);
        people[3] = new Teacher("smith",40,20000);
        people[4] = new Teacher("black",50,30000);
        for (int i = 0 ; i < people.length ; i++) {
            System.out.println(people[i].say());
            if (people[i] instanceof Student){
                ((Student)people[i]).study();
            }else if (people[i] instanceof Teacher){
                ((Teacher)people[i]).teach();
            }
        }
    }
}
